package com.sxbang.bms.controller;

import com.alibaba.fastjson.JSONObject;
import com.sxbang.bms.base.result.Results;
import com.sxbang.bms.dto.UserDto;
import com.sxbang.bms.model.SysUser;
import com.sxbang.bms.service.LoginService;
import com.sxbang.bms.service.UserService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author lmm
 * @date 2019/4/12 0012  15:56.
 */
@RestController
public class TestController {

    @Autowired
    private UserService userService;

    @Autowired
    public LoginService loginService;
    /**
     * 根据id获取
     *
     * @param id id
     * @return ResponseBean
     */
/*    @GetMapping("/{id}")
    @ApiOperation(value = "获取用户信息", notes = "根据用户id获取用户详细信息")//描述
    @ApiImplicitParam(name = "id", value = "用户ID", required = true, example = "0", dataType = "long", paramType = "path")//请求参数
    public SysUser user(@PathVariable Long id) {
        return userService.getUserById(id);
    }*/

    /*@RequestMapping(value = "/doLogin" ,method = RequestMethod.POST)
    @ApiOperation(value = "用户登录", notes = "获取token")//描述
    @ApiImplicitParams({
            @ApiImplicitParam(name = "username", required = true),
            @ApiImplicitParam(name = "password", required = true),
    })
    public JSONObject Login(String username, String password) {
        JSONObject data= loginService.getUerByUsernameAndPassword(username, password);
        return  data;
    }*/


    /**
     * 创建用户
     *
     * @param userDto userDto
     * @return ResponseBean
     * @author tangyi
     * @date 2018/8/26 14:34
     */
    @PostMapping(value = "/addUser")
    @ApiOperation(value = "创建用户", notes = "创建用户")
    @ApiImplicitParam(name = "userDto", value = "用户实体user", required = true, dataType = "UserDto")
    public  Results<SysUser> saveUser(@RequestBody UserDto userDto) {
        userDto.setStatus(1);
        userService.save(userDto,1);
        // 保存用户
        return Results.success();
    }


}
